import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;


public class WriteXMLFile 
{
	
	private Element eventRes;
	private Document doc;
	private XMLOutputter xmlOutputter;
	private long id = 0L;
	
	public WriteXMLFile()
	{
		File xmlFile = new File("file.xml");
		eventRes = new Element("events");
		doc = new Document(eventRes);
		//doc.setRootElement(eventRes);
		
		xmlOutputter = new XMLOutputter();
		
		xmlOutputter.setFormat(Format.getPrettyFormat());
		
	}
	
	public void toJDOM(String name, String message, String time)
	{
		Element res = new Element("event");
		
		res.setAttribute(new Attribute("id", String.valueOf(id)));
		res.addContent(new Element("name").setText(name));
		res.addContent(new Element("time").setText(time));
		res.addContent(new Element("descripion").setText(message));
		this.id++;
		
		doc.getRootElement().addContent(res);
		
		try {
			xmlOutputter.output(doc, new FileWriter("file.xml"));
		} catch (IOException e) {
			e.printStackTrace();

		}
	}

}
